package space.xxhui.dao

import org.mybatis.scala.mapping.{Insert, JdbcType, ResultMap, XSQL}
import space.xxhui.model.WordFreq

/**
 * @author HitvzByHui
 *         date 2021-09-12
 */
object WordFreqDao extends Serializable  {

  val ItemResultMap = new ResultMap[WordFreq] {
    id(column = "id", property = "id")
    result(column = "word", property = "word", jdbcType = JdbcType.VARCHAR)
    result(column = "date", property = "date", jdbcType = JdbcType.VARCHAR)
    result(column = "count", property = "count", jdbcType = JdbcType.INTEGER)
  }

  var incrInsert = new Insert[WordFreq]{
    def xsql: XSQL =
      <xsql>
        insert into word_freq
        (word,date,`count`)
        value
        (
        #{{word}},
        #{{date}},
        #{{count}}
        )
        on duplicate key update
        `count`=`count`+values(`count`);
      </xsql>
  }

}
